package modelo.mapeado;

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import java.awt.color.*;
import java.awt.image.*;

public class Conversion {
   
    public BufferedImage toBufferedImage(Image image) {
    	
       if(image instanceof BufferedImage ) 
                return((BufferedImage)image);
       else {
                image = new ImageIcon(image).getImage();
                BufferedImage bufferedImage = new BufferedImage(
                                                      image.getWidth(null),
                                                      image.getHeight(null),
                                                      BufferedImage.TYPE_INT_RGB);
                Graphics g = bufferedImage.createGraphics();
                g.drawImage(image,0,0,null);
                g.dispose();
                return(bufferedImage);
       }
    }
 
    static BufferedImage convertToGrayscale(BufferedImage source) {

        ColorConvertOp op = new ColorConvertOp( ColorSpace.getInstance(ColorSpace.CS_GRAY),null);
        BufferedImage imagenGris = op.filter(source, null);
        return (imagenGris);
 
    }
           
}
